package parser

import (
	"ZeroToAll-Go/crawler/engine"
	"regexp"
)

const cityListRex = `<a href="(http://localhost:8080/mock/www.zhenai.com/zhenghun/[0-9a-z]+)"[^>]*>([^<]+)</a>`

func ParseCityList(contents []byte) engine.ParseResult {
	compile := regexp.MustCompile(cityListRex)
	matches := compile.FindAllSubmatch(contents, -1)
	result := engine.ParseResult{}

	for _, match := range matches {
		result.Items = append(result.Items, string(match[2]))
		result.Requests = append(result.Requests, engine.Request{
			Url:        string(match[1]),
			ParserFunc: ParseCity,
		})
	}

	return result
}
